# _*_ coding : utf-8 _*_
# @Time : 2024-04-04 20:34
# @Author : haowen
# @File : test
# @Project : p2024-hyperthyroidism-screening
# 这里是测试DdataParser.py区域

import os
import re


# 定义一个函数，用于筛选出指定文件夹中的所有图片文件
def get_all_images(folder_path):
    image_files = []
    files_last_name = []
    for root, dirs, files in os.walk(folder_path):
        for file in files:
            if file.lower().endswith((".png", ".jpg", ".jpeg", ".gif")):
                image_files.append(os.path.join(root, file))
                files_last_name.append(os.path.basename(file))

    return image_files,files_last_name


# 指定文件夹路径
folder_path = "二院累计数据20240402"

# 调用函数获取所有图片文件列表
image_files,files_last_name = get_all_images(folder_path)

# 打印所有筛选出的图片文件路径
for img_file,file_last_name in zip(image_files,files_last_name):
    print(img_file)
    print(file_last_name)
    # 使用re.match()进行匹配
    match = re.match(r'(\d+)_(\d+)_(\d+)_.*_([A-Z])_\d+\.jpg', file_last_name)

    if match:
        patient_number = match.group(1)
        date_number = match.group(2)
        letter_code = match.group(4)

        print("Patient Number:", patient_number)
        print("Date Number:", date_number)
        print("Letter Code:", letter_code)
    else:
        print("No match found.")